<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JohnsonSmile的博客</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    {{template "comm/link.html"}}
</head>
<body class="lay-blog">
{{template "comm/header.html" .}}
<div class="container-wrap">
    <div class="container">
        <div class="contar-wrap">
            <div class="item">
                <div class="item-box  layer-photos-demo1 layer-photos-demo">
                    <form class="layui-form" action="" method="post">
                        <div class="layui-form-item">
                            <label class="layui-form-label">昵称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="name" required lay-verify="required" placeholder="请输入昵称"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">邮箱</label>
                            <div class="layui-input-inline">
                                <input type="text" name="email" required lay-verify="required" placeholder="请输入邮箱"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="password" required lay-verify="required"
                                       placeholder="请输入密码" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">确认密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="password1" required lay-verify="required"
                                       placeholder="请输入确认密码" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" type="button">登录</button>
                                <button class="layui-btn layui-btn-primary" lay-submit lay-filter="register">注册
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{{template "comm/footer.html"}}

<script>
    //Demo
    layui.use(['form', "jquery"], function () {
        var form = layui.form;
        $ = layui.jquery;

        //监听提交
        form.on('submit(register)', function (data) {
            console.log(JSON.stringify(data.field));
            $.post("/register", data.field, function (resp) {
                console.log(resp);
                if (resp.code == 0) {
                    layer.msg("注册成功!");
                    if (resp.action) {
                        setTimeout(function () {
                            window.location.href = resp.action;
                        }, 300);
                    }
                } else {
                    layer.msg("注册失败!" + resp.msg);
                }
            }, "json").error(function () {
                layer.msg("网络异常！");
            });
            return false;
        });

    });
</script>
</body>
</html>